//
//  ToolHelper.m
//  HuaRun2
//
//  Created by admin on 2017/9/19.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "ToolHelper.h"

@implementation ToolHelper

+(void)callWithPhoneNum:(NSString *)phoneNum{
    BOOL isEmpty = [NSString isemptyStr:phoneNum];
    if (isEmpty) {
        return;
    }
    if ([phoneNum isEqualToString:@" "]) {
        return;
    }

    
    if (TARGET_IPHONE_SIMULATOR) {
        
        NSLog(@"模拟器不支持打电话");
        return;
    }
    
    
    //    去空格
    phoneNum = [phoneNum stringByReplacingOccurrencesOfString:@" " withString:@""];
    //    去- 如 135-6789-1234
    phoneNum = [phoneNum stringByReplacingOccurrencesOfString:@"-" withString:@""];
    
    //telprompt
    NSString *urlstr = [NSString stringWithFormat:@"telprompt://%@",phoneNum];
    
    NSURL *url = [NSURL URLWithString:urlstr];
    //    NSDictionary *option;
    
    NSLog(@"\n\n拨打的号码:%@\n\n",url);
    
    
    //    第一种方式
    if (![[UIApplication sharedApplication] canOpenURL:url]) {
        
        //        [XHNRequest showMsg:@"拨打失败"];
        return;
    }
    
    CGFloat systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
    NSLog(@"%f",systemVersion);
    
    [[UIApplication sharedApplication] openURL:url];
    
}

+ (void)openWebWithUrlStr:(NSString *)str {
    BOOL isEmpty = [NSString isemptyStr:str];
    if (isEmpty) {
        return;
    }
    if ([str isEqualToString:@" "]) {
        return;
    }

//    NSString *iTunesLink;
//    iTunesLink = @"www.baidu.com";
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

+ (void)openEamilWithEmailStr:(NSString *)str {
    BOOL isEmpty = [NSString isemptyStr:str];
    if (isEmpty) {
        return;
    }
    if ([str isEqualToString:@" "]) {
        return;
    }
    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:
                                                [NSString stringWithFormat:@"mailto://%@", str] ]];
//                                                @"mailto://781178325@qq.com"]];
}
+ (BOOL)copyWithText:(NSString*)text {
    BOOL isEmpty = [NSString isemptyStr:text];
    if (isEmpty) {
        return NO;
    }
    if ([text isEqualToString:@" "]) {
        return NO;
    }

    UIPasteboard *pboard = [UIPasteboard generalPasteboard];
    pboard.string = text;
    return YES;
}

@end
